﻿using Starring.Framework.Factory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using LigerMVC.Business.ICore;
using LigerMVC.Entities;
using LigerMVC.Common;

namespace LigerMVC.Web.Application
{
    public class SystemController : Controller
    {
        private readonly IUserBusiness _userBusiness;

        public SystemController(IUserBusiness userBusiness)
        {
            _userBusiness = userBusiness; 
        }

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult UserList()
        {
            return View();
        }
        public ActionResult UserDetail()
        {
            return View();
        }

      
        public ActionResult GetUserGridData(QuerySimpleDescriptor descriptor)
        {
            var data = _userBusiness.GetPagedUser(descriptor.Convert());
            return Json(data);
        }
        [HttpGet]
        public ActionResult GetUserDetailData(int id)
        {
            var data = _userBusiness.GetUser(id);
            return Json(data);
        }

        public ActionResult SaveUser(CF_User user)
        {
            try
            {

                var data = _userBusiness.SaveUser(user);
                return Json(new
                {
                    Success = true
                });
            }
            catch (Exception err)
            {
                return Json(new
                {
                    Success = false,
                    Message = err.Message
                });
            }
        }
    }
}
